package start.demo01.array;

import com.alibaba.fastjson.JSON;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

public class ArrTest {

//    private static Logger log= LoggerFactory.getLogger(ArrTest.class);
    /**
     *
     * @param args
     */
    static String[] s;
    public static void main(String[] args){
//        String[] a=new String[2];
//        System.out.println(a[0]);
        System.out.println(s);
    }
    static int a;
    static{
        System.out.println("static"+test());
    }
    static{
        a=test();
    }
    public static int test(){
        System.out.println("test:"+a);
        return ++a;
    }
    @Test
    public void arrCopy(){
        String[] arr={"1","2","3","4","5"};
        //删除4号元素
        //将指定源数组中的数组从指定位置复制到目标数组的指定位置。
//        System.arraycopy(arr,4,arr,3,1);
//        arr[arr.length-1]=null;
//        System.out.println(JSON.toJSONString(arr));

        String[] arr2=new String[4];
        System.arraycopy(arr,0,arr2,0,3);
        System.arraycopy(arr,4,arr2,3,1);
        System.out.println(JSON.toJSONString(arr2));
    }

    @Test
    public void t3(){
        List<String> list =new ArrayList<>();
        list.add("dsad");
        System.out.println(list.size());
        for(String s:list){
            System.out.println(s);
        }

    }
    @Test public void toStr(){
        List<String> list=new ArrayList<>();
        list.add("321");
        list.add("321");
        StringBuilder builder=new StringBuilder();
        for(String s:list){
            builder.append(","+s);
        }
        String s = builder.toString();
        System.out.println(s.substring(1));
    }

    @Test
    public void t4(){
        List<String> list=new ArrayList<>();
        list.add("wq");
        System.out.println(list.contains("wq"));
        System.out.println(list.contains("w"));
        System.out.println(list.contains(null));

    }
    @Test
    public void t5(){
        Collections.synchronizedMap(new HashMap<>());
    }
    @Test
    public void t6(){
        List<String> list=new ArrayList<>();
        list.add("we");
        list.add("二次");
        list.add("规范");
        System.out.println(list);
//        String[] objects = (String[])list.toArray();
        String s = JSON.toJSONString(list);
//        String arr="[\"we\",\"二次\", \"规范\"]";
//        List<String> list1= JSONArray.parseArray(arr,String.class);
//        System.out.println(list1);
    }
    @Test
    public void t7(){
        List<Integer> list=new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        Iterator<Integer> iterator = list.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
            iterator.remove();
        }
    }
}
